Skip to content

[Win32] Return unrounded value in FontMetrics.getAverageCharacterWidth#2496

Merged
HeikoKlare merged 1 commit intoeclipse-platform:masterfrom
wahlbrink:fix-2461
Mar 3, 2026
Merged

[Win32] Return unrounded value in FontMetrics.getAverageCharacterWidth#2496
HeikoKlare merged 1 commit intoeclipse-platform:masterfrom
wahlbrink:fix-2461

Conversation

@wahlbrink
Copy link
Contributor

Fixes: #2461

@github-actions
Copy link
Contributor

github-actions bot commented Sep 10, 2025

Test Results

  176 files  ±0    176 suites  ±0   27m 0s ⏱️ +37s
4 694 tests ±0  4 672 ✅ ±0   22 💤 ±0  0 ❌ ±0 
6 520 runs  ±0  6 368 ✅ ±0  152 💤 ±0  0 ❌ ±0 

Results for commit 1712521. ± Comparison against base commit f9cbbf7.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the proposal! Since FontMetrics is a kind of central class (thus adapting it is critical) some more information about potential impacts (such as on the various consumers in the Eclipse Platform) and how far they were or need to be tested would be good. Also some information on how to test and reproduce changes in behavior would be nice.

@ptziegler fyi, as Draw2d's TextUtilities make use of this method

*/
public double getAverageCharacterWidth() {
return getAverageCharWidth();
return DPIUtil.pixelToPoint((float)handle.tmAveCharWidth, getZoom());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add a method converting doubles instead of trimming to float and then converting back?

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation of FontMetrics#getAverageCharacterWidth() obviously returns imprecise results when not at 100% zoom. The method has been introduced to deal with character widths not being integers on MacOS without adapting the Win32 implementation to also return precise autoscaled values: 0aa46cf

This fix resolves the mentioned issue and since we are very early in the development cycle, we should merge this to have several weeks of implicit testing for any potential regression that we may not anticipate now.

The value for getAverageCharacterWidth was rounded, even though its
method signature returns a double. The unrounded value provides a better
estimation of the average character width for non-integer zoom factors.

Fixes: eclipse-platform#2461
@HeikoKlare HeikoKlare merged commit 695bc20 into eclipse-platform:master Mar 3, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Win32] FontMetrics.getAverageCharacterWidth should return unrounded value

2 participants